package com.t174.car.controller;

import com.t174.car.dao.ComponentsDao;
import com.t174.car.entity.Components;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/compone")
@Scope("prototype")
public class ComponentsController {
    @Autowired
    ComponentsDao componentsDao;
    @RequestMapping("/comquery")
    @ResponseBody
    public List<Components> show(){
        return  componentsDao.qeruy();
    }
   @RequestMapping("/addcomponents")
    @ResponseBody
    public int addcomponents(Components components){
        return  componentsDao.AddComponents(components);
   }
    @RequestMapping("/deletecomponents")
    @ResponseBody
    public int del(String ids){
        String[] ss = ids.split("-");
        Integer[] myids = new Integer[ss.length] ;
        for(int i=0;i<ss.length;i++){
            System.out.println(ss[i]);
            myids[i] = Integer.parseInt(ss[i]) ;
        }
        return componentsDao.delComponents(myids);
    }
    @RequestMapping("/showid")
    @ResponseBody
    public Components idComponents(int id){
        return  componentsDao.getComponents(id);
    }
    @RequestMapping("udateComponents")
    @ResponseBody
    public  int udateComponents(Components components){
        return  componentsDao.updateComponents(components);
    }
    @RequestMapping("/getCount")
    @ResponseBody
    public  int getCount(int id){
        return  componentsDao.getCountById(id);
    }

}
